{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Snapshot\n", "\n", "This notebook sheds some light on the snapshot of instruments.\n", "\n", "__NOTE__: this notebook uses a depreated `Loop` construct for some of its examples. Please, instead, refer to [__Working with snapshots__ notebook from `docs/examples/DataSet`](DataSet/Working%20with%20snapshots.ipynb)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Logging hadn't been started.\n", "Activating auto-logging. Current session state plus future input saved.\n", "Filename : C:\\Users\\a-halakh\\.qcodes\\logs\\command_history.log\n", "Mode : append\n", "Output logging : True\n", "Raw input log : False\n", "Timestamping : True\n", "State : active\n", "Qcodes Logfile : C:\\Users\\a-halakh\\.qcodes\\logs\\200324-30512-qcodes.log\n", "False\n" ] } ], "source": [ "import json\n", "import os\n", "from pprint import pprint\n", "\n", "import qcodes as qc\n", "from qcodes.instrument_drivers.mock_instruments import DummyInstrument\n", "from qcodes.station import Station\n", "\n", "from qcodes_loop.loops import Loop\n", "\n", "# For this tutorial, we initialise our favourite pair of mock instruments,\n", "# a DMM and a DAC\n", "\n", "dmm = DummyInstrument('dmm', gates=['v1', 'v2'])\n", "dac = DummyInstrument('dac', gates=['ch1', 'ch2'])\n", "\n", "station = Station(dmm, dac)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The main point of having a `Station` is that it *snapshots* the state of all added instruments. But what does that mean? Recall that an instrument is, loosely speaking, a collection of `Parameters`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parameter snapshot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}\n" ] } ], "source": [ "# Each parameter has a snapshot, containing information about its current value,\n", "# when that value was set, what the allowed values are, etc.\n", "pprint(dmm.v1.snapshot())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instrument snapshot" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'functions': {},\n", " 'name': 'dmm',\n", " 'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_IDN',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'IDN',\n", " 'name': 'IDN',\n", " 'post_delay': 0,\n", " 'raw_value': {'firmware': None,\n", " 'model': 'dmm',\n", " 'serial': None,\n", " 'vendor': None},\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': '',\n", " 'vals': '',\n", " 'value': {'firmware': None,\n", " 'model': 'dmm',\n", " 'serial': None,\n", " 'vendor': None}},\n", " 'v1': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'v2': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v2',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v2',\n", " 'name': 'v2',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}},\n", " 'submodules': {}}\n" ] } ], "source": [ "# Each instrument has a snapshot that is basically the snapshots of all the parameters\n", "pprint(dmm.snapshot())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sweep snapshot" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'parameter': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_ch1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'Gate ch1',\n", " 'name': 'ch1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'values': [{'first': 0.0, 'last': 10.0, 'num': 25, 'type': 'linear'}]}\n" ] } ], "source": [ "# When running QCoDeS loops, something is being swept. This is controlled with the `sweep` of a parameter.\n", "# Sweeps also have snapshots\n", "a_sweep = dac.ch1.sweep(0, 10, num=25)\n", "pprint(a_sweep.snapshot())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loop/Measurement snapshot" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'__class__': 'qcodes.loops.ActiveLoop',\n", " 'actions': [{'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}],\n", " 'delay': 0,\n", " 'sweep_values': {'parameter': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_ch1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'Gate ch1',\n", " 'name': 'ch1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'values': [{'first': 0.0,\n", " 'last': 1.0,\n", " 'num': 10,\n", " 'type': 'linear'}]},\n", " 'then_actions': []}\n" ] } ], "source": [ "# All this is of course nice since a snapshot is saved every time a measurement is \n", "# performed. Let's see this in action with a Loop.\n", "\n", "# This is a qcodes_loop.loop, sweeping a dac gate and reading a dmm voltage\n", "lp = Loop(dac.ch1.sweep(0, 1, num=10), 0).each(dmm.v1)\n", "\n", "# before the loop runs, the snapshot is quite modest; it contains the snapshots of\n", "# the two involved parameters and the sweep\n", "pprint(lp.snapshot())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started at 2020-03-24 18:47:43\n", "DataSet:\n", " location = 'data/2020-03-24/#014_{name}_18-47-43'\n", " | | | \n", " Setpoint | dac_ch1_set | ch1 | (10,)\n", " Measured | dmm_v1 | v1 | (10,)\n", "Finished at 2020-03-24 18:47:43\n", "{'__class__': 'qcodes.data.data_set.DataSet',\n", " 'arrays': {'dac_ch1_set': {'__class__': 'qcodes.data.data_array.DataArray',\n", " 'action_indices': (),\n", " 'array_id': 'dac_ch1_set',\n", " 'full_name': 'dac_ch1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'is_setpoint': True,\n", " 'label': 'Gate ch1',\n", " 'name': 'ch1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'shape': (10,),\n", " 'unit': 'V',\n", " 'vals': ''},\n", " 'dmm_v1': {'__class__': 'qcodes.data.data_array.DataArray',\n", " 'action_indices': (0,),\n", " 'array_id': 'dmm_v1',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'is_setpoint': False,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'shape': (10,),\n", " 'unit': 'V',\n", " 'vals': ''}},\n", " 'formatter': 'qcodes.data.gnuplot_format.GNUPlotFormat',\n", " 'io': '\",\n", " 'location': 'data/2020-03-24/#014_{name}_18-47-43',\n", " 'loop': {'__class__': 'qcodes.loops.ActiveLoop',\n", " 'actions': [{'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}],\n", " 'delay': 0,\n", " 'sweep_values': {'parameter': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_ch1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'Gate ch1',\n", " 'name': 'ch1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'values': [{'first': 0.0,\n", " 'last': 1.0,\n", " 'num': 10,\n", " 'type': 'linear'}]},\n", " 'then_actions': [],\n", " 'ts_end': '2020-03-24 18:47:43',\n", " 'ts_start': '2020-03-24 18:47:43',\n", " 'use_threads': 'data/dataset'},\n", " 'station': {'components': {},\n", " 'config': None,\n", " 'default_measurement': [],\n", " 'instruments': {'dac': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'functions': {},\n", " 'name': 'dac',\n", " 'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_IDN',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'IDN',\n", " 'name': 'IDN',\n", " 'post_delay': 0,\n", " 'raw_value': {'firmware': None,\n", " 'model': 'dac',\n", " 'serial': None,\n", " 'vendor': None},\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': '',\n", " 'vals': '',\n", " 'value': {'firmware': None,\n", " 'model': 'dac',\n", " 'serial': None,\n", " 'vendor': None}},\n", " 'ch1': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_ch1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'Gate ch1',\n", " 'name': 'ch1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'ch2': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dac_ch2',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dac',\n", " 'inter_delay': 0,\n", " 'label': 'Gate ch2',\n", " 'name': 'ch2',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}},\n", " 'submodules': {}},\n", " 'dmm': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'functions': {},\n", " 'name': 'dmm',\n", " 'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_IDN',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'IDN',\n", " 'name': 'IDN',\n", " 'post_delay': 0,\n", " 'raw_value': {'firmware': None,\n", " 'model': 'dmm',\n", " 'serial': None,\n", " 'vendor': None},\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': '',\n", " 'vals': '',\n", " 'value': {'firmware': None,\n", " 'model': 'dmm',\n", " 'serial': None,\n", " 'vendor': None}},\n", " 'v1': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v1',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v1',\n", " 'name': 'v1',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0},\n", " 'v2': {'__class__': 'qcodes.instrument.parameter.Parameter',\n", " 'full_name': 'dmm_v2',\n", " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", " 'instrument_name': 'dmm',\n", " 'inter_delay': 0,\n", " 'label': 'Gate v2',\n", " 'name': 'v2',\n", " 'post_delay': 0,\n", " 'raw_value': 0,\n", " 'ts': '2020-03-24 '\n", " '18:47:43',\n", " 'unit': 'V',\n", " 'vals': '',\n", " 'value': 0}},\n", " 'submodules': {}}},\n", " 'parameters': {}}}\n" ] } ], "source": [ "# After the loop has run, the dataset contains more information, in particular the \n", "# snapshots for ALL parameters off ALL instruments in the station\n", "data = lp.run('data/dataset')\n", "pprint(data.snapshot())\n", "\n", "# This is the snapshot that get's saved to disk alongside your data. \n", "# It's worthwhile familiarising yourself with it, so that you may retrieve\n", "# valuable information down the line!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 1 }